Skip to content

Conversation

bradchristensen
Copy link
Contributor

Minimal repro, in test case format:

// @strict: true
// @target: esnext
// @noEmit: false
// @jsx: react-jsx

/// <reference path="/.lib/react16.d.ts" />

<div>
    Foo
</div>;

Behavior with [email protected]

import { jsx as _jsx } from "react/jsx-runtime";
/// <reference path="react16.d.ts" />
_jsx("div", { children: "Foo" });

Behavior with tsgo

"Foo" is truncated to "Fo":

import { jsx as _jsx } from "react/jsx-runtime";
/// <reference path="react16.d.ts" />
_jsx("div", { children: "Fo" });

@Copilot Copilot AI review requested due to automatic review settings September 9, 2025 10:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the last character of JSX text nodes was being truncated during the compilation process. The issue was in the fixupWhitespaceAndDecodeEntities function which was using an incorrect slice range when extracting text content from JSX nodes.

  • Fixes character truncation in JSX text nodes by correcting slice bounds
  • Updates test baselines to reflect the corrected text extraction behavior

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.

File Description
internal/transformers/jsxtransforms/jsx.go Fixes the slice range bug by changing lastNonWhitespace to lastNonWhitespace+1 and corrects a typo
testdata/baselines/reference/submodule/* Updates test baseline files to reflect the corrected JSX text output

@bradchristensen
Copy link
Contributor Author

@microsoft-github-policy-service agree

// (lastNonWhitespace === -1 is a special flag to detect whether the first line is all whitespace.)
if firstNonWhitespace != -1 && lastNonWhitespace != -1 {
addLineOfJsxText(acc, text[firstNonWhitespace:lastNonWhitespace], initial)
addLineOfJsxText(acc, text[firstNonWhitespace:lastNonWhitespace+1], initial)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, original code was:

acc = addLineOfJsxText(acc, text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1));

@gabritto gabritto enabled auto-merge September 9, 2025 16:18
@gabritto gabritto added this pull request to the merge queue Sep 9, 2025
Merged via the queue into microsoft:main with commit 6c49566 Sep 9, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants